﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinook.Core.DaoInterface;
using Chinook.Core.DomainModel;
using Chinook.Facade.Ioc;

namespace Chinook.Facade
{
    public class InvoiceAppService : IInvoiceAppService
    {
        private ICustomerDao _customerDao;

        public ICustomerDao CustomerDao
        {
            get
            {
                if (_customerDao != null)
                    return _customerDao;
                _customerDao = new FacadeExposer().CustomerDao;
                return _customerDao;
            }
        }

        private IInvoiceDao _invoiceDao;

        public IInvoiceDao InvoiceDao
        {
            get
            {
                if (_invoiceDao != null)
                    return _invoiceDao;
                _invoiceDao = new FacadeExposer().InvoiceDao;
                return _invoiceDao;
            }
        }

        //function to get customer by id
        public Customer GetCustomerByID(long CustomerID)
        {            
            var ocustomer = CustomerDao.GetById(CustomerID,false);
            return ocustomer;
        }

        //function to get invoice by id 
        public Invoice GetInvoiceByID(long InvoiceID)
        {
            var oinvoice = InvoiceDao.GetById(InvoiceID, false);
            return oinvoice;
        }
       
        //function to save an invoice
        public Invoice SaveInvoice(Invoice oinvoice)
        {
            InvoiceDao.Save(oinvoice);
            return null;
        }
       
        //public EmployeeSaveResponse SaveEmployee(EmployeeSaveRequest employeeSaveRequest)
        //{
        //    EmployeeSaveResponse result = new EmployeeSaveResponse();
        //    try
        //    {
        //        var input = employeeSaveRequest.employeeViewModel;
        //        Employee e = new Employee()
        //        {
        //            Title = input.Title,
        //            FirstName = input.FirstName,
        //            LastName = input.LastName,
        //            BirthDate = input.BirthDate,
        //            StreetAddressLine1 = input.StreetAddressLine1,
        //            StreetAddressLine2 = input.StreetAddressLine2,
        //            City = input.City,
        //            State = input.State,
        //            Country = input.Country,
        //            PostalCode = input.PostalCode,
        //            Email = input.Email,
        //            Phone = input.Phone,
        //            Fax = input.Fax,
        //            //ReportsTo=input.Title,
        //            HireDate = input.HireDate
        //        };

        //        EmployeeDao.Save(e);
        //        result.Success = true;
        //        employeeSaveRequest.employeeViewModel.Id = e.Id;//Set the autoincrement number
        //        result.employeeViewModel = employeeSaveRequest.employeeViewModel;
        //    }

        //    catch (Exception ex)
        //    {
        //        result.Success = false;
        //        result.Message = ex.Message;
        //    }
        //    return result;

        //}
        


    }
}
